// pages/teacher/mine/center/mine.js
var app = getApp();
import {teacher_active} from "../../../../asserts/js/common/barList";
import {post} from "../../../../asserts/js/request";
import drawQrcode from '../../../../asserts/js/qc';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barList: teacher_active(1),
    headImg: "/asserts/imgs/temp/head.jpeg",
    top: app.globalData.bottom + 'px',
    qrCodeUrl:"",
    userInfoList:[],
    operateList: [
      // 20210912 隐藏
      // {
      //   src: "/asserts/imgs/operation/mine-stu.png",
      //   name: "我的学员"
      // },
      {
        src: "/asserts/imgs/operation/mine-course.png",
        name: "班级作业"
      },
      {
        src: "/asserts/imgs/operation/mine-teacher-code.png",
        name: "教师二维码"
      },
      {
        src: "/asserts/imgs/operation/mine-orgchange.png",
        name: "机构切换"
      },
      {
        src: "/asserts/imgs/operation/mine-about.png",
        name: "关于我们"
      }
    ],
    pickerShow: false,
    classChooseShow: false,
    classList: [],
    qrShow: false,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var this_ = this;
    var list = [
      {
        key: 'Id',
        value: app.globalData.teacherInfo.teacherId
      },
      {
        key: '姓名',
        value: app.globalData.teacherInfo.teacherName
      },
      {
        key: '机构',
        value: app.globalData.teacherInfo.orgName
      }
    ]
    this.setData({
      userInfoList: list,
      headImg: app.globalData.teacherInfo.teacherPhoto
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  operateChoose: function(e) {
    console.log(e);
    var this_ = this;
    // 我的学员需要抛出事件
    if (e.detail.name == "我的学员") {
      wx.navigateTo({
        url: '/pages/teacher/mine/mineStu/mineStu',
      })
    }
    // 机构切换
    if (e.detail.name == "机构切换") {
      wx.navigateTo({
        url: '/pages/teacher/login/login',
      })
      return;
    }
    // 课程列表
    if (e.detail.name == "班级作业") {
      wx.navigateTo({
        url: '/pages/teacher/mine/mineClass/mineClass',
      })
    }
    // 教师二维码
    if (e.detail.name == "教师二维码") {
      post("queryClass",{
        teacherId: app.globalData.teacherInfo.teacherId,
        orgId: app.globalData.teacherInfo.orgId
      }).then(data => {
        var list = data.classInfo.map(item => {
          return {
            name: item.className,
            code: item.classId,
            qrCodeUrl: item.qrCodeUrl,
            choosed: false
          };
        })
        this_.setData({
          classList: list,
          classChooseShow: true
        })
      });
    }
  },
  chooseClass: function(e) {
    var id = e.detail.code;
    
    this.setData({
      qrCodeUrl:  e.detail.qrCodeUrl
    })
    

    //const query = wx.createSelectorQuery()

    // drawQrcode({
    //   width: 200,
    //   height: 200,
    //   canvasId: 'myQrcode',
    //   text: id+"",
    //   image: {
    //     imageResource: app.globalData.teacherInfo.teacherPhoto,
    //     //imageResource: e.detail.qrCodeUrl,
    //     dx: 70,
    //     dy: 70,
    //     dWidth: 60,
    //     dHeight: 60
    //   }
    // })
    this.setData({
      qrShow: true,
      classChooseShow: false
    })
  },
  closeQr: function() {
    this.setData({
      qrShow: false
    })
  }
})